<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var str = "good-good-study"
        //good
        //good
        //study

        var reg = /(\w+)-(\w+)-(\w+)/
        //test()
        //exec()
        reg.exec(str)

        console.log(RegExp.$_);  //good-good-study   完整的字串
        console.log(RegExp.$1);  //good
        console.log(RegExp.$2);  //good
        console.log(RegExp.$3);  //study

        // RegExp.$n   n的范围1-9 指的是正则表达式匹配的第n个字串

        var reg = /\{\{(.*)\}\}/
        var str = "{{msg}}"
        if (reg.test(str)) {
            var name = RegExp.$1
            console.log(name);

        }


    </script>
</body>

</html>